package com.ljw.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljw.dto.GetFreeRoomDto;
import com.ljw.entity.Room;
import com.ljw.entity.Type;
import com.ljw.service.RoomService;
import com.ljw.service.TypeService;
import com.ljw.vo.RoomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 客房信息表 前端控制器
 * </p>
 *
 * @author ljw
 * @since 2020-07-25
 */
@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private RoomService roomService;

    @PostMapping("/getFreeRoom")
    public List<Room> getFreeRoom(@RequestBody GetFreeRoomDto getFreeRoomDto){
        return roomService.getFreeRoom(getFreeRoomDto);
    }

    @GetMapping("/findAll")
    public Page<RoomVo> findAll(@RequestParam int current, @RequestParam int size){
        Page<RoomVo> page = new Page<>(current,size);
        return roomService.findAll(page);
    }

    @PostMapping("/update")
    @Transactional
    public String update(@RequestBody Room room){
        boolean b = roomService.updateById(room);
        return b?"OK":"ERROR";
    }

}

